package com.dididoctor.patient.wxapi;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.dididoctor.patient.Activity.ConstantValue;
import com.dididoctor.patient.R;
import com.tencent.mm.sdk.modelbase.BaseReq;
import com.tencent.mm.sdk.modelbase.BaseResp;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.sdk.openapi.WXAPIFactory;

public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {

    private static final String TAG = "MicroMsg.SDKSample.WXPayEntryActivity";

    private IWXAPI api;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pay_result);

        api = WXAPIFactory.createWXAPI(this, ConstantValue.APP_ID);
        api.handleIntent(getIntent(), this);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        api.handleIntent(intent, this);
    }

    @Override
    public void onReq(BaseReq req) {
    }

    @Override
    public void onResp(BaseResp resp) {

        int code = resp.errCode;
        switch (code) {
            case 0://支付成功后的界面
//                MyToast.DefaultmakeText(getApplicationContext(), "支付成功", 0);
                Intent intent = new Intent("PayOkRecedir");
                intent.putExtra("code",0);
                sendBroadcast(intent);
                break;
            case -1:
//                MyToast.DefaultmakeText(getApplicationContext(), "签名错误、未注册APPID、项目设置APPID不正确、注册的APPID与设置的不匹配、您的微信账号异常等。", 0);
                break;
            case -2://用户取消支付后的界面
//                MyToast.DefaultmakeText(getApplicationContext(), "用户取消支付后的界面", 0);
                break;
        }
        finish();
    }


}